package mx.com.crowdgine.display.animation.mocap;

import junit.framework.Assert;

import org.junit.Test;

public class ASFFileTest {

	@Test
	public void testASFFileParse() {
		
		String fileName = "Assets/Mocap/12.asf";
		
		ASFFile asfFile = new ASFFile(fileName);
		
		Assert.assertEquals("1.10", asfFile.getVersion());
		Assert.assertEquals("VICON", asfFile.getName());
		Assert.assertEquals(1.0f, asfFile.getUnitsMass());
		Assert.assertEquals("deg", asfFile.getUnitsAngle());
		
		String [] orders = asfFile.getRootOrders();
		Assert.assertNotNull(orders);
		Assert.assertEquals("TX", orders[0]);
		Assert.assertEquals("TY", orders[1]);
		Assert.assertEquals("TZ", orders[2]);
		Assert.assertEquals("RX", orders[3]);
		Assert.assertEquals("RY", orders[4]);
		Assert.assertEquals("RZ", orders[5]);
		
		Assert.assertEquals("XYZ", asfFile.getRootAxis());
		
		float [] rootPosition = asfFile.getRootPosition();
		Assert.assertEquals(1.0f, rootPosition[0]);
		Assert.assertEquals(2.0f, rootPosition[1]);
		Assert.assertEquals(3.0f, rootPosition[2]);
		
		float [] rootOrientation = asfFile.getRootOrientation();
		Assert.assertEquals(5.0f, rootOrientation[0]);
		Assert.assertEquals(6.0f, rootOrientation[1]);
		Assert.assertEquals(7.0f, rootOrientation[2]);
		
		float [] direction = null;
		float [] axisOrientation = null;
		String [] dof = null;
		
		
		ASFBone lhipjoint = asfFile.getBone("lhipjoint");
		Assert.assertEquals(1, lhipjoint.getId());
		Assert.assertEquals(0, lhipjoint.getParentId());
		direction = lhipjoint.getDirection();
		Assert.assertEquals(0.734638f, direction[0]);
		Assert.assertEquals(-0.55547f, direction[1]);
		Assert.assertEquals(0.389564f, direction[2]);
		Assert.assertEquals(2.86753f, lhipjoint.getLength());
		axisOrientation = lhipjoint.getAxisOrientation();
		Assert.assertEquals(1.1f, axisOrientation[0]);
		Assert.assertEquals(2.6546f, axisOrientation[1]);
		Assert.assertEquals(3.654f, axisOrientation[2]);
		Assert.assertEquals("XYZ", lhipjoint.getAxisInitialRotationOrder());
		Assert.assertNull(lhipjoint.getDof());
		Assert.assertNotNull(lhipjoint.getLimits());
		Assert.assertEquals(0, lhipjoint.getLimits().size());
		
		
		ASFBone lfemur = asfFile.getBone("lfemur");
		Assert.assertEquals(2, lfemur.getId());
		Assert.assertEquals(lhipjoint.getId(), lfemur.getParentId());
		direction = lfemur.getDirection();
		Assert.assertEquals(0.34202f, direction[0]);
		Assert.assertEquals(-0.939693f, direction[1]);
		Assert.assertEquals(0.0f, direction[2]);
		Assert.assertEquals(5.95383f, lfemur.getLength());
		axisOrientation = lfemur.getAxisOrientation();
		Assert.assertEquals(0.0f, axisOrientation[0]);
		Assert.assertEquals(0.0f, axisOrientation[1]);
		Assert.assertEquals(20.0f, axisOrientation[2]);
		Assert.assertEquals("XYZ", lfemur.getAxisInitialRotationOrder());
		Assert.assertNotNull(lfemur.getDof());
		dof = lfemur.getDof();
		Assert.assertEquals("rx", dof[0]);
		Assert.assertEquals("ry", dof[1]);
		Assert.assertEquals("rz", dof[2]);
		Assert.assertNotNull(lfemur.getLimits());
		Assert.assertEquals(3, lfemur.getLimits().size());
		Assert.assertEquals(-160.0f, lfemur.getLimits().get(0).getLowerBound());
		Assert.assertEquals(20.0f, lfemur.getLimits().get(0).getUpperBound());
		Assert.assertEquals(-70.0f, lfemur.getLimits().get(1).getLowerBound());
		Assert.assertEquals(70.0f, lfemur.getLimits().get(1).getUpperBound());
		Assert.assertEquals(-60.0f, lfemur.getLimits().get(2).getLowerBound());
		Assert.assertEquals(70.0f, lfemur.getLimits().get(2).getUpperBound());
		
		
		ASFBone lfoot = asfFile.getBone("lfoot");
		Assert.assertEquals(4, lfoot.getId());
		Assert.assertEquals(3, lfoot.getParentId());
		direction = lfoot.getDirection();
		Assert.assertEquals(0.0456794f, direction[0]);
		Assert.assertEquals(-0.125503f, direction[1]);
		Assert.assertEquals(0.991041f, direction[2]);
		Assert.assertEquals(2.00909f, lfoot.getLength());
		axisOrientation = lfoot.getAxisOrientation();
		Assert.assertEquals(-90f, axisOrientation[0]);
		Assert.assertEquals(7.62852e-016f, axisOrientation[1]);
		Assert.assertEquals(20f, axisOrientation[2]);
		Assert.assertEquals("XYZ", lfoot.getAxisInitialRotationOrder());
		Assert.assertNotNull(lfoot.getDof());
		dof = lfoot.getDof();
		Assert.assertEquals("rx", dof[0]);
		Assert.assertEquals("rz", dof[1]);
		Assert.assertNotNull(lfoot.getLimits());
		Assert.assertEquals(2, lfoot.getLimits().size());
		Assert.assertEquals(-45.0f, lfoot.getLimits().get(0).getLowerBound());
		Assert.assertEquals(90.0f, lfoot.getLimits().get(0).getUpperBound());
		Assert.assertEquals(-70.0f, lfoot.getLimits().get(1).getLowerBound());
		Assert.assertEquals(20.0f, lfoot.getLimits().get(1).getUpperBound());
		
		
		
	}
	
}
